package com.bbznb.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Cro implements WebMvcConfigurer {

    @Autowired
    private MyInter myInter;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  // 所有接口都允许跨域
                .allowedOrigins("http://localhost:3000")    // 允许跨域访问的域名
                .allowedMethods("*")    // 允许任何方法（POST、GET等）
                .allowedHeaders("*")    // 允许任何请求头
                .allowCredentials(true) // 允许携带凭证（如cookie）
                .maxAge(3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInter)
                .addPathPatterns("/**")
                .excludePathPatterns("/api/auth/login", "/api/auth/register","/api/ai/chat"
                       );
    }
}
